/**
 * 
 */
package com.lemote.action.account;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lemote.action.BaseAction;
import com.lemote.core.PropertyFilter;
import com.lemote.entity.Permission;
import com.lemote.exception.AppException;
import com.lemote.service.account.PermissionService;
import com.lemote.utils.CheckUtils;

/**
 * @author wuhui
 *
 * 下午02:36:38
 */
@Component("permissionAction")
public class PermissionAction extends BaseAction<Permission, PermissionService> {

	private Permission entity;
	
	@Override
	public String delete() throws AppException {
		
		if (ids!=null&&ids.length()>0) {
			entityService.delete(CheckUtils.stringParse(ids));
		}
		return SUCCESS;
	}

	
	@Override
	public String input() throws AppException {
		prepare();
		return SUCCESS;
	}

	
	@Override
	public String list() throws AppException {
		
		List<PropertyFilter> filters = PropertyFilter.buildFromHttpRequest(request);
		page = entityService.search(page, filters);
		return SUCCESS;
	}

	
	@Override
	public void prepareModel() throws AppException {
		if (id != null) {
			entity = entityService.get(id);
		} else {
			entity = new Permission();
		}
		
	}

	
	@Override
	public String save() throws AppException {
		setBackUrl("permission/list.htm");
		if (entity!=null) {
			if (entity.getId()==null) {
				entityService.add(entity);
			}else {
				entityService.update(entity);
			}
			return GLOBALSUCCESS;
		} 
		return ERROR;
	}

	@Autowired
	@Override
	public void setEntityService(PermissionService entityService) {
		
		this.entityService = entityService;
	}

	
	public Permission getEntity() {
		return entity;
	}


	public void setEntity(Permission entity) {
		this.entity = entity;
	}


	public Permission getModel() {
		
		return entity;
	}

}
